package com.frame.common.exception;

import com.frame.common.RespEnum;

/**
 * @author Flying
 * @Description
 * @date 12:44 2018-08-27
 **/


import com.frame.json.GsonUtil;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class AuthException extends RuntimeException{


    @Getter
    private Integer code;

    @Getter
    private String message;

    public AuthException(){}

    /**
     * @param respEnum 枚举信息
     */
    public AuthException(RespEnum respEnum){
        super(respEnum.getDesc());
        this.code = respEnum.getCode();
        this.message = respEnum.getDesc();
        log.info(respEnum.getCode()+":"+respEnum.getDesc());
    }

    /**
     *
     * @param respEnum 枚举信息
     * @param e 异常
     */
    public AuthException(RespEnum respEnum, Throwable e){
        super(respEnum.getDesc(),e);
        log.error(respEnum.getCode()+":"+respEnum.getDesc()+"|cause:"+e.getCause()+"|message:"+e.getMessage(),e);
        this.code = respEnum.getCode();
        this.message = respEnum.getDesc();
    }
    /**
     *
     * @param respEnum 枚举信息
     * @param arguments 参数
     */
    public AuthException(RespEnum respEnum, Object arguments){
        super(respEnum.getDesc());
        log.info(respEnum.getCode()+":"+respEnum.getDesc()+"|arguments:"+ GsonUtil.GsonString(arguments));
        this.code = respEnum.getCode();
        this.message = respEnum.getDesc();
    }

    /**
     *
     * @param respEnum 枚举信息
     * @param throwable 异常
     * @param arguments 参数
     */
    public AuthException(RespEnum respEnum, Object  arguments, Throwable e){
        super(respEnum.getDesc(),e);
        log.error(respEnum.getCode()+":"+respEnum.getDesc()+"|cause:"+e.getCause()+"|message:"+e.getMessage()+"|arguments:"+ GsonUtil.GsonString(arguments),e);
        this.code = respEnum.getCode();
        this.message = respEnum.getDesc();
    }

    /**
     *
     */
    public AuthException(Integer code, String description, Throwable e){
        super(description,e);
        log.error(code + ":"+ description +"|cause:"+e.getCause()+"|message:"+e.getMessage()+"|arguments:"+ e);
        this.code = RespEnum.SERVER_ERROR.getCode();
        this.message =  RespEnum.SERVER_ERROR.getDesc();
    }

    /**
     *
     */
    public AuthException(String description, Throwable e){
        super(description,e);
        log.error(description +"|cause:"+e.getCause()+"|message:"+e.getMessage()+"|arguments:"+ e);
        this.code = RespEnum.SERVER_ERROR.getCode();
        this.message =  RespEnum.SERVER_ERROR.getDesc();
    }



}
